package com.example.mvvmtest.utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.example.mvvmtest.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

import java.util.List;

public class ImageLoaderBaseAdapter extends BaseAdapter {
    private LayoutInflater inflater;
    private List<String> picture_uri;

    public ImageLoaderBaseAdapter(Context context,List<String> picture_uri) {
        this.inflater = LayoutInflater.from(context);
        this.picture_uri = picture_uri;
    }

    @Override
    public int getCount() {
        return picture_uri.size();
    }

    @Override
    public Object getItem(int i) {
        return picture_uri.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        /*
        ViewHolder holder;
        if (view == null) {
            view = inflater.inflate(R.layout.lsv_item_image_loader, null);
            holder = new ViewHolder();
            holder.iv_lin = (ImageView) view.findViewById(R.id.iv_lin);
            view.setTag(holder);
        }
        holder = (ViewHolder) view.getTag();
        // 创建DisplayImageOptions对象并进行相关选项配置
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.ic_launcher)// 设置图片下载期间显示的图片
                .showImageForEmptyUri(R.drawable.ic_launcher)// 设置图片Uri为空或是错误的时候显示的图片
                .showImageOnFail(R.drawable.ic_launcher)// 设置图片加载或解码过程中发生错误显示的图片
                .cacheInMemory(true)// 设置下载的图片是否缓存在内存中
                .cacheOnDisk(true)// 设置下载的图片是否缓存在SD卡中
                .displayer(new RoundedBitmapDisplayer(20))// 设置成圆角图片
                .build();// 创建DisplayImageOptions对象
        // 使用ImageLoader加载图片
        imageLoader.displayImage(picture_uri[position], holder.iv_lin, options);
*/
        return view;
    }

    /**
     * 控件缓存类
     * @author 邹奇
     *
     */
    private static class ViewHolder {
        ImageView iv_lin;
    }

}
